package br.ufpe.cin.camid.core.config;

import br.ufpe.cin.camid.core.agents.AgentConfig;
import br.ufpe.cin.camid.core.agents.AgentListener;
import br.ufpe.cin.camid.core.events.Core;
import br.ufpe.cin.camid.core.events.EventBusListener;
import br.ufpe.cin.camid.core.lifecycle.ObjectRegistry;
import br.ufpe.cin.camid.core.lifecycle.factory.ManagedObjectFactory;
import br.ufpe.cin.camid.core.lifecycle.factory.SimpleManagedObjectFactory;

import com.google.common.eventbus.EventBus;
import com.google.inject.AbstractModule;
import com.google.inject.matcher.Matchers;

public class CoreModule extends AbstractModule 
{
	private EventBus eventBus;
	
	private AgentConfig agentConfig;
	
	public CoreModule()
	{
		super();
		eventBus = new EventBus();
		agentConfig = new AgentConfig();
	}
	
	@Override
	protected void configure() 
	{
		bind(ObjectRegistry.class).toInstance(new ObjectRegistry());
		bind(ManagedObjectFactory.class).to(SimpleManagedObjectFactory.class);
		bind(EventBus.class).annotatedWith(Core.class).toInstance(eventBus);
		bindListener(Matchers.any(), new EventBusListener(eventBus, Core.class));
		bindListener(Matchers.any(), new AgentListener(agentConfig));
	}

}
